package com.wffz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wffz.comm.utils.DateUtils;
import com.wffz.dto.RewardDTO;
import com.wffz.mapper.RewardMapper;
import com.wffz.po.Reward;
import com.wffz.po.ShareRecord;
import com.wffz.service.RewardService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author sunlei
 * @className RewardServiceImpl
 * @Description
 * @date 2023-04-09 17:18
 **/
@Service
public class RewardServiceImpl implements RewardService {

    @Resource
    private RewardMapper rewardMapper;

    @Override
    public List<RewardDTO> queryMyReward(long userId) {
        List<RewardDTO> dtoList = rewardMapper.getRewardUserList(userId);
        if (dtoList == null || dtoList.size() == 0) {
            dtoList = new ArrayList<>();
            QueryWrapper<Reward> wrapper = new QueryWrapper<>();
            List<Reward> list = rewardMapper.selectList(wrapper);
            RewardDTO rewardDTO = null;
            for (Reward r : list) {
                rewardDTO = new RewardDTO();
                rewardDTO.setId(r.getId());
                rewardDTO.setRewardContent(r.getRewardContent());
                rewardDTO.setRewardBtn(r.getRewardBtn());
                rewardDTO.setRewardIcon(r.getRewardIcon());
                rewardDTO.setRewardTitle(r.getRewardTitle());
                rewardDTO.setRemark(r.getRemark());
                rewardDTO.setUserId(null);
                dtoList.add(rewardDTO);
            }
        }
        return dtoList;
    }
}
